package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.GoodsDetailsActivity;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.HotStoreGoods;
import com.weixin.paleituo.help.RecycleViewHolder;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

/**
 * Author yichao
 * Time  2018/4/4 11:13
 * Dest  ${TODO}
 */

public class StoreHomeAdapter extends BaseRecycleAdapter<HotStoreGoods> {
    public StoreHomeAdapter(Context context, List datas) {
        super(context, datas, R.layout.item_store_home);
    }


    @Override
    protected void setData(RecycleViewHolder holder, final HotStoreGoods hotStoreGoods, int position) {
    ImageView imageView= holder.getItemView(R.id.iv_goods_icon_item_store_home);
   TextView tvgoodsName=   holder.getItemView(R.id.tv_goodsname_item_store_home);
    TextView tvMoney=    holder.getItemView(R.id.tv_money_item_store_home);
     TextView saleNumber=   holder.getItemView(R.id.tv_sale_number_item_store_home);
    TextView tvNomal= holder.getItemView(R.id.tv_nomar_price_item_store_home);
   ImageView ivVip=  holder.getItemView(R.id.iv_vip_item_store_home);

        String specialSales = hotStoreGoods.getSpecialSales();
        if (!StringUtils.isEmpty(specialSales)){
            ivVip.setVisibility(View.VISIBLE);
            tvNomal.setVisibility(View.VISIBLE);
            tvMoney.setTextColor(UIUtils.getColor(R.color.c_29CE7E));
            tvMoney.setText("￥"+UIUtils.getMoney(Double.valueOf(specialSales)));
            tvNomal.setText("￥"+UIUtils.getMoney(hotStoreGoods.getPrice()));

        }else {
            ivVip.setVisibility(View.INVISIBLE);
            tvNomal.setVisibility(View.INVISIBLE);
            tvMoney.setTextColor(UIUtils.getColor(R.color.c_ed5240));
            tvMoney.setText("￥"+UIUtils.getMoney(hotStoreGoods.getPrice()));
        }

        UIUtils.loadImageView(mContext,hotStoreGoods.getUrl(),imageView);
        tvgoodsName.setText(hotStoreGoods.getName()+"");
        int salenum = hotStoreGoods.getSalenum();
        if (salenum!=0){
            saleNumber.setText("已售"+salenum);
        }else {
            saleNumber.setText("");
        }


        holder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoodsDetailsActivity.startActivity(mContext,hotStoreGoods.getGid());
            }
        });


    }
}
